#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: spd-sxmcc
"""
@author: lyndon
@time Created on 2019/2/23 16:53
@desc
"""
# from flask import Flask
# from op_mysql import OPMysql
# from op_postgres import OPPostgre
# # 创建mysql数据库连接池
# opm = OPMysql('mysql://root:newpasswd@192.168.100.161:3306/OLINGO')
# # 创建postgres数据库连接池
# # opp = OPPostgre()
# print('name:' + __name__)
# app = Flask(__name__)
# # app.config.from_object('analyzer.conf.settings')
#
#
# @app.route('/')
# def index():
#     urls = str(app.url_map)
#     return 'Index Page' + urls




from urlparse3.urlparse3 import parse_url


def getconninfo2(login_str):
    """
    make login_str of db to a dict
    the dict examples :
        -- {'username': 'pyspd_admin', 'database': 'spd_mgr', 'fragment': None, 'charset': 'utf8', 'dbtype': 'mysql',
        'host': '192.168.100.161', 'query': {}, 'password': 'pyspd_admin_1Q', 'port': 3306}

           {'username': None, 'database': 'sjtd', 'fragment': None, 'charset': 'utf8', 'dbtype': 'hive',
           'host': '10.231.32.131', 'query': OrderedDict([('auth_mechanism', 'GSSAPI')]),
           'password': None, 'port': 10000}
    :param login_str:
    :return: dict
    """
    db_infos = parse_url(login_str).__dict__
    db_infos['dbtype'] = db_infos.pop('scheme')
    db_infos['host'] = db_infos.pop('domain')
    db_infos['database'] = db_infos.pop('path').replace('/', '')
    db_infos['charset'] = 'utf8'
    db_infos['port'] = int(db_infos.pop('port'))
    return db_infos

